package com.zqxq.lottery.entity.o2o.product;

import com.zqxq.lottery.entity.po.product.ProductPO;
import com.zqxq.lottery.entity.vo.product.ProductVO;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
public class ProductO2O {

    public static ProductVO toVO(ProductPO po) {
        if (po == null) {
            return null;
        }
        ProductVO productVO = new ProductVO();
        productVO.setId(String.valueOf(po.getId()));
        productVO.setCalss(po.getCalss());
        productVO.setType(po.getType());
        productVO.setDetailType(po.getDetail_type());
        productVO.setModel(po.getModel());
        productVO.setColor(po.getColor());
        productVO.setVersion(po.getVersion());
        productVO.setDescription(po.getDescription());
        productVO.setLongDescription(po.getLong_description());
        productVO.setImgUrl(po.getImg_url());
        productVO.setPrice(String.valueOf(po.getPrice()));
        productVO.setExchangeRate(String.valueOf(po.getExchange_rate()));
        productVO.setStatus(po.getStatus());
        productVO.setSort(po.getSort());
        productVO.setCreateTime(String.valueOf(po.getCreate_time()));
        productVO.setUpdateTime(String.valueOf(po.getUpdate_time()));
        return productVO;
    }

    public static ProductPO toPO(ProductVO vo) {
        if (vo == null) {
            return null;
        }
        ProductPO productPO = new ProductPO();
        if(!StringUtils.isEmpty(vo.getId())){
            productPO.setId(Long.valueOf(vo.getId()));
        }
        productPO.setCalss(vo.getCalss());
        productPO.setType(vo.getType());
        productPO.setDetail_type(vo.getDetailType());
        productPO.setModel(vo.getModel());
        productPO.setColor(vo.getColor());
        productPO.setVersion(vo.getVersion());
        productPO.setDescription(vo.getDescription());
        productPO.setLong_description(vo.getLongDescription());
        productPO.setImg_url(vo.getImgUrl());
        if(!StringUtils.isEmpty(vo.getPrice())){
            productPO.setPrice(new BigDecimal(vo.getPrice()));
        }
        if(!StringUtils.isEmpty(vo.getExchangeRate())) {
            productPO.setExchange_rate(new BigDecimal(vo.getExchangeRate()));
        }
        productPO.setStatus(vo.getStatus());
        productPO.setSort(vo.getSort());
        return productPO;
    }
}
